import React from 'react';
import {connect} from 'react-redux';
import moment from 'moment';
import {messages} from "share/common";
import {Icon, Button} from 'antd';
import messagesService from "./messages-center.service";
import 'styles/messages-center/messages-center-detail.scss'
import menuRoute from "routes/menuRoute";

class MessagesCenterDetail extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: true,
      record: null,
      id: this.props.params.id,
      messagesCenter: menuRoute.getRouteItem('messages-center', 'key').url,
    };
  }

  componentWillMount() {
    this.getMessagesCenterDetail();
  }

  //获取消息详情
  getMessagesCenterDetail = () => {
    const {id} = this.state;
    messagesService.getMessagesCenterDetail(id).then(res => {
      this.setState({
        record: res.data,
      })
    }).catch(err => {

    })
  };

  render() {
    const {record, messagesCenter} = this.state;
    return (
        record ?
          <div className={'messages-center-detail'}>
            <div style={{margin: "28px 0", fontSize: 24, fontWeight: 600, color: "black"}}>
              {record.title}
            </div>
            <div>
              <img src={record.imageLink} style={{maxWidth: 720, margin: "20px 0"}}/>
            </div>
            <div style={{width: 720}}>
              <div  style={{textIndent: 15, marginBottom: 80}}
                    className={'text-area-content'}
                    dangerouslySetInnerHTML={{__html: record.content}}/>
            </div>
            <div style={{margin: "30px 0"}}>
              <a onClick={() => {this.context.router.push(messagesCenter)}}><Icon type="rollback"/>{messages("common.back")/*返回*/}</a>
            </div>
          </div>
          :
          <div></div>
    )
  }

}

MessagesCenterDetail.contextTypes = {
  router: React.PropTypes.object
};

function mapStateToProps(state) {
  return {
    user : state.login.user,
    language : state.main.language,
  }
}

export default connect(mapStateToProps)(MessagesCenterDetail);
